package cmbc.honorcredit.entity;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

import org.apache.log4j.Logger;

public class PropertiesUtils {
	
	private static Logger logger = Logger.getLogger(PropertiesUtils.class);
	
	public static String BLAZE_ADB_PATH = "";
	public static String BLAZE_ENTRY_NAME = "";
	public static String BLAZE_ENTRY_POINT = "";
	public static String HOST_NAME;  
	public static String PORT;  
	public static String USE_HTTPS;  
	public static String IP_FILTER;  
	
	static {
		InputStream inputStream1 = null;
		InputStream inputStream2 = null;
		try {
			inputStream1 = PropertiesUtils.class.getClassLoader()
					.getResourceAsStream("config/iresetting.properties");
			Properties props = new Properties();
			props.load(inputStream1);

			BLAZE_ADB_PATH = props.getProperty("blaze.adb.path").trim();
			BLAZE_ENTRY_NAME = props.getProperty("blaze.entry.name").trim();
			BLAZE_ENTRY_POINT = props.getProperty("blaze.entry.point").trim();
			IP_FILTER = props.getProperty("ip.filter").trim();
			
			logger.info("Read iresetting.properties file:BLAZE_ADB_PATH["+BLAZE_ADB_PATH+"],"
					+ "BLAZE_ENTRY_NAME["+BLAZE_ENTRY_NAME+"],BLAZE_ENTRY_POINT["+BLAZE_ENTRY_POINT+"],IP_FILTER["+IP_FILTER+"]");
			
			inputStream2 = PropertiesUtils.class.getClassLoader()
					.getResourceAsStream("resource/key.properties");
			props = new Properties();
			props.load(inputStream2);
			HOST_NAME = props.getProperty("hostname").trim();
			PORT = props.getProperty("port").trim();
			USE_HTTPS = props.getProperty("useHTTPS").trim();
			logger.info("Read key.properties file:HOST_NAME["+HOST_NAME+"],"
					+ "PORT["+PORT+"],USE_HTTPS["+USE_HTTPS+"]");
			

		} catch (Exception e) {
			BLAZE_ADB_PATH = "";
			BLAZE_ENTRY_NAME = "";
			BLAZE_ENTRY_POINT = "";
			HOST_NAME = "";
			PORT = "";
			USE_HTTPS = "";
			logger.warn("Error in read iresetting.properties/key.properties use default value:"
					+ "BLAZE_ADB_PATH["+BLAZE_ADB_PATH+"],BLAZE_ENTRY_NAME["+BLAZE_ENTRY_NAME+"],BLAZE_ENTRY_POINT["+BLAZE_ENTRY_POINT+"],HOST_NAME["+HOST_NAME+"],"
					+ "PORT["+PORT+"],USE_HTTPS["+USE_HTTPS+"]");
			e.printStackTrace();
		} finally{
			if(inputStream1 != null){
				try {
					inputStream1.close();
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
			if(inputStream2 != null){
				try{
					inputStream2.close();
				}catch(IOException e){
					e.printStackTrace();
				}
			}
		}
	}

}
